﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace view.Action
{
    /// <summary>
    /// 处理登录请求
    /// </summary>
    public class Register : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request.HttpMethod.ToLower() == "get")
            {
                JU.Common.CommonHelper.ClearUserSession();
            }
            string loginName = context.Request.Form["loginName"].Trim();
            if (context.Request.Params["type"] == "1")
            {
                if (loginName.Length > 0)
                {
                    if (JU.BLL.LoginManager.LoginNameIsUsable(loginName))
                    {
                        context.Response.Write(1);
                        context.Response.End();
                    }
                }
            }
            else if (context.Request.Params["type"] == "2")
            {
                string loginPwd = context.Request.Form["loginPwd"];
                if (loginName.Length > 0 && loginPwd.Length == 32)
                {
                    if (JU.BLL.LoginManager.Register(loginName, loginPwd))
                    {
                        context.Response.Write(1);
                        context.Response.End();
                    }
                }
            }
            context.Response.Write(0);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}